﻿using Client.Components.PrinterPanel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Client.Test
{
    /// <summary>
    /// Interaction logic for FrmTestPrinterPanel.xaml
    /// </summary>
    public partial class FrmTestPrinterPanel : Window
    {
        public FrmTestPrinterPanel()
        {
            InitializeComponent();
        }
    }

    public class FrmTestPrinterPanel_ViewModel : BaseViewModel
    {
        public FrmTestPrinterPanel_ViewModel()
        {
            initCommand();
            initData_PrinterPanel();
        }

        public Command CMD_GetPanel0Info { get; private set; }
        public Command CMD_TestUpdateData { get; private set; }

        void initCommand()
        {
            this.CMD_GetPanel0Info = new Command(getPanel0Info);
            this.CMD_TestUpdateData = new Command(TestUpdateData);
        }

        void getPanel0Info(object objWindow)
        {
            string msg = $"控件数据验证结果:{this.UcPrinterPanel_IsValidated}\r\n选择打印机:{this.UcPrinterPanel_SelectedPrinter?.DisplayName}\r\n选择纸张:{this.UcPrinterPanel_SelectedPaperSize?.DisplayName}";
            WPFControls.MessageBox.ShowInformationDialog(objWindow as Window, msg);
        }

        void TestUpdateData(object args)
        {
            if (args is Client.Components.UcPrinterPanel target)
            {
                target.UpdateData("Microsoft Print to PDF", "A4");
            }
        }

        #region UcPrinterPanel 代码示例

        void initData_PrinterPanel(string configPrinterName = "")
        {
            // 可以在后台指定打印机列表只显示哪些打印机；也可以不设置控件会帮你设置
            var temp = Client.Components.PrinterPanel.PrinterUtils.GetPrinterList(isContainUpdateListItem: false) // 设置是否显示刷新选项, 这里如果采用自行赋值的方式, 建议不显示刷新选项
                // .Skip(1) // 自定义打印列表
                .ToList();

            // 按照优先排序
            this.UcPrinterPanel_PrinterList = Client.Components.PrinterPanel.PrinterUtils.PrinterOrderBy(temp, new List<string>() { "Fax", "OneNote for Windows 10" }, new List<string>() { "A5", "A4", "A3" });

            // 1. 设置选中默认打印机；也可以不设置，控件会帮你设置默认打印机。
            // this.UcPrinterPanel_SelectedPrinter = this.UcPrinterPanel_PrinterList.FirstOrDefault(i => i.DisplayName == Client.Components.PrinterPanel.PrinterUtils.GetDefaultPrinterName());

            // 2. 假设这是读取配置文件的打印机配置
            configPrinterName = "Fax";
            var matchPrinter = this.UcPrinterPanel_PrinterList.FirstOrDefault(i => i.DisplayName == configPrinterName);
            if (matchPrinter != null)
            {
                this.UcPrinterPanel_SelectedPrinter = matchPrinter;
            }
        }


        private bool _UcPrinterPanel_IsValidated;
        public bool UcPrinterPanel_IsValidated
        {
            get { return _UcPrinterPanel_IsValidated; }
            set
            {
                _UcPrinterPanel_IsValidated = value;
                this.OnPropertyChanged(nameof(UcPrinterPanel_IsValidated));
            }
        }

        private List<Printer> _UcPrinterPanel_PrinterList;
        public List<Printer> UcPrinterPanel_PrinterList
        {
            get { return _UcPrinterPanel_PrinterList; }
            set
            {
                _UcPrinterPanel_PrinterList = value;
                this.OnPropertyChanged(nameof(UcPrinterPanel_PrinterList));
            }
        }

        private Printer _UcPrinterPanel_SelectedPrinter;
        public Printer UcPrinterPanel_SelectedPrinter
        {
            get { return _UcPrinterPanel_SelectedPrinter; }
            set
            {
                _UcPrinterPanel_SelectedPrinter = value;
                this.OnPropertyChanged(nameof(UcPrinterPanel_SelectedPrinter));
            }
        }

        private PaperSize _UcPrinterPanel_SelectedPaperSize;
        public PaperSize UcPrinterPanel_SelectedPaperSize
        {
            get { return _UcPrinterPanel_SelectedPaperSize; }
            set
            {
                _UcPrinterPanel_SelectedPaperSize = value;
                this.OnPropertyChanged(nameof(UcPrinterPanel_SelectedPaperSize));
            }
        }

        #endregion



        private Printer _PrinterPanel1_SelectedPrinter;
        public Printer PrinterPanel1_SelectedPrinter
        {
            get { return _PrinterPanel1_SelectedPrinter; }
            set
            {
                _PrinterPanel1_SelectedPrinter = value;
                this.OnPropertyChanged("PrinterPanel1_SelectedPrinter");
            }
        }

        private PaperSize _PrinterPanel1_SelectedPagerSize;
        public PaperSize PrinterPanel1_SelectedPagerSize
        {
            get { return _PrinterPanel1_SelectedPagerSize; }
            set
            {
                _PrinterPanel1_SelectedPagerSize = value;
                this.OnPropertyChanged("PrinterPanel1_SelectedPagerSize");
            }
        }
    }
}